/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.qdu.servlet;

import com.qdu.entity.Dianzan;
import com.qdu.entity.User;
import com.qdu.service.DianzanService;
import com.qdu.service.impl.DianzanServiceImpl;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.swing.JOptionPane;

/**
 *
 * @author Lenovo
 */
@WebServlet("/dzans")
public class DianzanServlet extends HttpServlet{
    
    DianzanService dianzanService = new DianzanServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String jid=req.getParameter("jid");

        User user=new User();
        HttpSession session=req.getSession();
        user=(User)session.getAttribute("user");
        int id=user.getId();
        System.out.println("dz当前登录id："+id);
        
        if(dianzanService.hasZan(jid, id))
        {
            System.out.println("点赞成功");
            int Zan=dianzanService.addZan(jid);
            req.setAttribute("zan", Zan);
            req.setAttribute("jon", jid);
            req.getRequestDispatcher("/dzzz.jsp").forward(req, resp);
        }
        else
        {
            System.out.println("点赞失败");
            req.setAttribute("jon", jid);
            req.getRequestDispatcher("/dzzz2.jsp").forward(req, resp);
        }
        
    }
    
}
